package com.dhcc.controller;
import com.dhcc.util.RedisUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping(value = "/redis")
public class RedisController {

    // 注入redisUtils对象
    @Autowired
    RedisUtil redisUtils;

    /**
     * redis 存值
     * @param key redis 键
     * @param value redis 值
     */
    @RequestMapping("/setValue/{key}/{value}")
    @ResponseBody
    public String setValue(@PathVariable("key") String key,@PathVariable("value") String value) {
        redisUtils.set(key, value);
        return "true";
    }

    /**
     * redis 取值
     * @param key redis 键
     */
    @RequestMapping("/getValue/{key}")
    @ResponseBody
    public String getValue(@PathVariable("key") String key) {
        String value = (String) redisUtils.get(key);
        System.out.println(value);
        return value;
    }
}

